/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package back;

import core.SchoolMat;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import schoolMatSupport.IReader;

/**
 *
 * @author buben
 */
@ManagedBean(name = "reader")
@SessionScoped
public class ReaderBean {
    
    @EJB
    IReader r;
    
    @ManagedProperty(value="#{viewer}")
    viewerBean viewer;

    public void setViewer(viewerBean viewer) {
        this.viewer = viewer;
    }

    public viewerBean getViewer() {
        return viewer;
    }
    
    public String getPagePath(int i){
        return r.getPage(i);
    }
    
    public int getTotalPages(){
        return r.getTotalPages();
    }
    
    public List<String> getThumbnail(){
        return r.getThumbnails();
    }
    
    public String openEditor(SchoolMat mat){
       FacesContext context = FacesContext.getCurrentInstance();
       ServletContext servletContext = (ServletContext)context.getExternalContext().getContext();
       String location1 = servletContext.getRealPath("/");
       String location = servletContext.getRealPath(mat.getMatPath());
       viewer.setActualPage(1);
       viewer.setActualZoom(96);
       
       r.openDocument(mat, location1, location);
        
        return "docViewer?faces-redirect=true";
    }
    
    
}
